package com.cskaoyan.market.util.wx;

import com.cskaoyan.market.db.domain.MarketUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;

public class SessionUtils {
    public SessionUtils() {
    }
    public static Session getSession(SecurityManager securityManager){
       SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        return session;
    }
    public static MarketUser getUser(SecurityManager securityManager){
        SecurityUtils.setSecurityManager(securityManager);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        MarketUser user = (MarketUser) session.getAttribute("user");
        return user;
    }
    public static Integer getUserId(SecurityManager securityManager){
        MarketUser user = getUser(securityManager);
        if (user == null){
            return 0;
        }
        return user.getId();
    }
}
